// components/number-select-seach/index.js
import {
  search
} from '../../api/number-select'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    _id: {
      type: Number,
      value: -1
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    refresh: true,
    page: {
      currentPage: 1,
      size: 999
    },
    value: '',
    columns: [],
    show: false,
    name: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClear() {
      this.setData({
        value: ''
      })
      this.fetchData()
    },
    onChange(event) {
      this.setData({
        value: event.detail
      })
    },
    onConfirm(event) {
      console.log(event)
    },
    onRefresh() {
      this.setData({
        refresh: true,
        page: {
          ...this.data.page,
          currentPage: 1
        }
      })
      this.fetchData();
      setTimeout(() => {
        this.setData({
          refresh: false
        })
      }, 1200)
    },
    fetchData() {
      search({
        ...this.data.page,
        numSettingsIds: this.properties._id,
        value: this.data.value
      }, res => {
   
        this.setData({
          columns: [{
           
            value: '不限'
          }, ...res.records]
        })
      })
    },
    toggle() {
      this.setData({
        show: !this.data.show
      })
      this.fetchData()
    },
    onSelect(event) {
      const item = event.currentTarget.dataset.item;
      this.triggerEvent('select', item.value);
      this.setData({
        name: item.value
      })
      this.toggle();
    },
    reset() {
      this.setData({
        name: ''
      })
    }
  }
})